package com.kaidi.dibankecloud.widget;

import android.app.Activity;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.kaidi.dibankecloud.R;
import com.kaidi.dibankecloud.databinding.PopupTipsBinding;

/**
 * Created by Administrator on 2017/1/6.
 */

public class TipsPopupWindow extends PopupWindow{
    private Context context;
    public TipsPopupWindow(Context context, Drawable tipIcon, String tipText, int textColor) {
        super(context);
        this.context = context;
        PopupTipsBinding binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.popup_tips, null, false);
        binding.setTipIcon(tipIcon);
        binding.setTipText(tipText);
        binding.setTipColor(textColor);
        setContentView(binding.getRoot());
        setWidth((int) context.getResources().getDimension(R.dimen.tips_width));
        setHeight((int) context.getResources().getDimension(R.dimen.tips_height));
        ColorDrawable dw = new ColorDrawable(0000000000);
        setBackgroundDrawable(dw);
        setFocusable(true);
        update();
    }

    public void showPopupWindow(View anchor){
        if(!isShowing()){
            showAtLocation(anchor, Gravity.CENTER,0,0);
            Window window = ((Activity) context).getWindow();
            WindowManager.LayoutParams lp = window.getAttributes();
            lp.alpha = 0.5f;
            window.setAttributes(lp);
        }
    }

}
